<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>

    <link rel="stylesheet" href="js/wangEditor.min.css"/>
    <script src="js/wangEditor.min.js"></script>
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.validate.min.js"></script>
    <script type="text/javascript" src="js/messages_zh.js"></script>
    <style>
        label.error {
            margin-left: 10px;
            color: red;
            font-size: small;
        }

        input.error {
            border: solid 1px red;
        }
    </style>

    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">酒店管理</a>
            <a>
              <cite>酒店信息</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>

<form id="form">
    酒店名称<input type="text" class="hotelname" id="hotelname" name="hotel">
    <hr>
    酒店地址<input type="text" class="hoteladdress" id="hoteladdress" name="hotel">
    <hr>
    酒店价格<input type="text" class="hotelprice" id="hotelprice" name="hotel">
    <hr>
    联系方式<input type="text" class="hotelphone" id="hotelphone" name="hotelphone">
    <hr>
    <input type="button" value="酒店信息设置" class="update">
</form>
</body>

<script>
    $(function () {
        $.ajax({
            type: "POST",
            url: "getHotelInfo",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                if (data != null) {
                    $("#hotelname").val(data.hotelName);
                    $("#hoteladdress").val(data.location);
                    $("#hotelprice").val(data.hotelPrice);
                    $("#hotelphone").val(data.hotelPhone);
                }else {
                    alert("数据获取失败")
                }
            }

        })
    })
</script>
<script>
    //开机执行
    $(function () {
        //表单验证
        $("#form").validate({
            rules: {
                hotel:{
                    required: true,
                },
                hotelphone:{
                    required: true,
                    minlength:11,
                    isMobile:true
                },
            },
            messages: {
                hotel:{
                    required:"请输入信息",
                },
                hotelphone:{
                    required: "请输入信息",
                    minlength:"请正确填写手机号码",
                    isMobile:"请正确填写手机号码"
                },
            }
        });
    });
    jQuery.validator.addMethod("isMobile", function(value, element) {
        var length = value.length;
        var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "请正确填写手机号码");

</script>

<script type="text/javascript">
    $(document).on("click",".update",function () {
        $.ajax({
            type: 'POST',
            url: "hotelInfoSave",
            contentType:"application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify({
                "hotelName":$("#hotelname").val(),
                "location":$("#hoteladdress").val(),
                "hotelPrice": $("#hotelprice").val(),
                "hotelPhone": $("#hotelphone").val()
            }),
            success: function(data){
                if(data){
                    window.location.reload()
                    alert("设置成功")
                }else {
                    alert("信息设置失败")
                }
            },
            error:function (data) {
                console.error("hhhhhhhhhhhh"+data);
            }
        })
    })
</script>



<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</html>